package com.servlets;

import com.domain.UserEntity;
import com.service.StudentService;
import com.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class RegisterServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");

        String sno = req.getParameter("sno");
        String sex = req.getParameter("sex");
        String address = req.getParameter("address");
        String hobby = req.getParameter("hobby");

        String username = req.getParameter("username");
        String pwd = req.getParameter("pwd");

        Integer snoLong = Integer.parseInt(sno);
        Integer sexInt = Integer.parseInt(sex);

        UserEntity userEntity = new UserEntity();
        userEntity.setUsername(username);
        userEntity.setSno(snoLong);
        userEntity.setSex(sexInt);
        userEntity.setAddress(address);
        userEntity.setHobby(hobby);
        userEntity.setPwd(pwd);

        StudentService studentService = new StudentServiceImpl();
        studentService.register(userEntity);


    }

}
